package com.lyz.ejb.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.ColumnResult;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.EntityResult;

/**
 * PartyGroup entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Entity
@NamedNativeQueries({
	@NamedNativeQuery(
		name="OrganizationTreeQuery",			
		query = "select party_id, party_name||decode(status,0,'',1,'(停用)','') party_name, pid, level party_Level, status" +
			"  from (select p.party_id        party_id," +
			"               pg.group_name     party_name," +
			"               prs.party_id_from pid, " +
			"				pg.status "+		
			"          from party p" +
			"          left join party_group pg" +
			"            on p.party_id = pg.party_id" +
			"          left join party_relationship prs" +
			"            on p.party_id = prs.party_id_to" +
			"         where p.party_type_id = 'PARTY_GROUP'" +
			"           and prs.party_relationship_type_id = 'GROUP_ROLLUP'" +
			"           and prs.role_type_id_from = 'PARENT_ORGANIZATION'" +
			"           and prs.role_type_id_to = 'ORGANIZATION_UNIT') t" +
			" connect by prior party_id = pid" +
			" start with pid = :rootOrgId",
		resultSetMapping="OrganizationTreeMapping"
	),
	@NamedNativeQuery(  //根据机构ID查询上级机构的partyGroup
		name="getParentPartyGroup",
		query=
			" select pg.party_id,pg.group_name,pg.federal_tax_id,pg.comments,pg.status,pg.create_date,pg.create_by,pg.last_modify_date,pg.group_name_abbr,pg.party_layer " +
			" from party_relationship pr,party_group pg " +
			" where pr.party_id_from = pg.party_id and pr.party_id_to = :orgId " +
			" and pr.role_type_id_from = 'PARENT_ORGANIZATION' and pr.role_type_id_to = 'ORGANIZATION_UNIT' " +
			" and pr.party_relationship_type_id = 'GROUP_ROLLUP'",
		resultSetMapping="parentPartyGroup"
	)
})
@SqlResultSetMappings({
	@SqlResultSetMapping(name="OrganizationTreeMapping", 
		entities={
		},
		columns={
		    @ColumnResult(name="party_id"),
		    @ColumnResult(name="party_name"),
		    @ColumnResult(name="pid"),
		    @ColumnResult(name="party_Level"),
		    @ColumnResult(name="status")
		}
	),
	@SqlResultSetMapping(
		name="parentPartyGroup",
		entities={
			@EntityResult(entityClass=com.lyz.ejb.entity.PartyGroup.class)
		}
	)
})
@Table(name = "PARTY_GROUP", uniqueConstraints = {})
public class PartyGroup implements java.io.Serializable {

	// Fields

	private String partyId;
	private String groupName;
	private String federalTaxId;
	private String comments;
	private String status;
	private Date createDate;
	private String createBy;
	private Date lastModifyDate;
	private String groupNameAbbr;
	private String partyLayer;
	private String parentOrgName;

	// Constructors

	/** default constructor */
	public PartyGroup() {
	}

	/** minimal constructor */
	public PartyGroup(String partyId) {
		this.partyId = partyId;
	}

	/** full constructor */
	public PartyGroup(String partyId, String groupName, String federalTaxId,
			String comments, String status, Date createDate, String createBy,
			Date lastModifyDate, String groupNameAbbr, String partyLayer) {
		this.partyId = partyId;
		this.groupName = groupName;
		this.federalTaxId = federalTaxId;
		this.comments = comments;
		this.status = status;
		this.createDate = createDate;
		this.createBy = createBy;
		this.lastModifyDate = lastModifyDate;
		this.groupNameAbbr = groupNameAbbr;
		this.partyLayer = partyLayer;
	}

	// Property accessors
	@Id
	@Column(name = "PARTY_ID", unique = true, nullable = false, insertable = true, updatable = true, length = 40)
	public String getPartyId() {
		return this.partyId;
	}

	public void setPartyId(String partyId) {
		this.partyId = partyId;
	}

	@Column(name = "GROUP_NAME", unique = false, nullable = true, insertable = true, updatable = true, length = 60)
	public String getGroupName() {
		return this.groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	@Column(name = "FEDERAL_TAX_ID", unique = false, nullable = true, insertable = true, updatable = true, length = 60)
	public String getFederalTaxId() {
		return this.federalTaxId;
	}

	public void setFederalTaxId(String federalTaxId) {
		this.federalTaxId = federalTaxId;
	}

	@Column(name = "COMMENTS", unique = false, nullable = true, insertable = true, updatable = true)
	public String getComments() {
		return this.comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	@Column(name = "STATUS", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATE_DATE", unique = false, nullable = true, insertable = true, updatable = true, length = 7)
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Column(name = "CREATE_BY", unique = false, nullable = true, insertable = true, updatable = true, length = 40)
	public String getCreateBy() {
		return this.createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LAST_MODIFY_DATE", unique = false, nullable = true, insertable = true, updatable = true, length = 7)
	public Date getLastModifyDate() {
		return this.lastModifyDate;
	}

	public void setLastModifyDate(Date lastModifyDate) {
		this.lastModifyDate = lastModifyDate;
	}

	@Column(name = "GROUP_NAME_ABBR", unique = false, nullable = true, insertable = true, updatable = true, length = 60)
	public String getGroupNameAbbr() {
		return this.groupNameAbbr;
	}

	public void setGroupNameAbbr(String groupNameAbbr) {
		this.groupNameAbbr = groupNameAbbr;
	}

	@Column(name = "PARTY_LAYER", unique = false, nullable = true, insertable = true, updatable = true, length = 40)
	public String getPartyLayer() {
		return this.partyLayer;
	}

	public void setPartyLayer(String partyLayer) {
		this.partyLayer = partyLayer;
	}

		
}